﻿<%@ Page Language="C#" MasterPageFile="~/Demo/DemoMaster.master" %>

<%@ Import Namespace="NetflixCatalog" %>
<%@ Import Namespace="System.Web.Services" %>
<%@ Import Namespace=" System.Linq" %>
<script runat="server">
    [WebMethod]
    public static IEnumerable GetModels(int num)
    {
        //sleep for 5 seconds
        System.Threading.Thread.Sleep(5000);
        NetflixCatalog catalog = new NetflixCatalog(new Uri("http://odata.netflix.com/Catalog/"));
        return catalog.Titles.Take(num);
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="demoheader" runat="Server">
    Cancel request
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="demosubheader" runat="Server">
    Use <span>cancel</span> function to abort a request and close the loading tag
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="democontent" runat="Server">
    <link rel="stylesheet" href="../css/pagination.css" />
    <script type="text/javascript" src="../jQueryClient/postback.js"></script>
    <script type="text/javascript" src="../jQueryClient/databind.js"></script>
    <script type="text/javascript" src="../jQueryClient/jTemplates.js"></script>
    <script type="text/javascript" src="../jQueryClient/pagination.js"></script>
    <script type="text/javascript" src="../jQueryClient/dataformat.js"></script>
    <script type="text/javascript" src="../jQueryClient/datejs.js"></script>
    <style type="text/css">
        #demo1 p
        {
            font-weight: bold;
            margin: 10px 0px 10px 0px;
        }
        #demo1content
        {
            padding: 10px;
            border: 3px solid #888;
        }
        
        #loading
        {
            background-color: White;
            border: 5px solid black;
            padding: 50px;
        }
        
         div#csharp
        {
            margin-top:20px;
        }
    </style>
    <div id="demo1content">
        <!-- The pagination will be shown here -->
        <div class="PaginationContainer">
        </div>
        <br style="clear: both;" />
        <!-- An empty div to show the actual table -->
        <div id="Container">
        </div>
        <!-- The template of the "repeater" -->
        <textarea id="template" style="display: none">
			<table>
				<tr>
					<th></th>
					<th></th>
					<th onclick="sort('Name')">Name</th>
					<th onclick="sort('AverageRating')">Average Rating</th>
					<th onclick="sort('Dvd.Available')">DVD Available</th>
					<th onclick="sort('DateModified')">Modified</th>
				</tr>
				{#foreach $T as d}
				<tr class="{#cycle values=['odd','even']}">
					<td> {$T.d$index + 1} </td>
					<td><img style="height: 75px;" src="{$T.d.BoxArt.SmallUrl}" /></td>
					<td> {$T.d.Name} </td>
					<td class="number"> 
						  {#if $T.d.AverageRating < 2} <span style="color: Red">{$T.d.AverageRating}</span> {#elseif $T.d.AverageRating
                        < 3} <span style="color: Orange">{$T.d.AverageRating}</span> {#else} {$T.d.AverageRating} {#/if}
					</td>
					<td> {$T.d.Dvd.Available ? 'Y' : 'N'} </td>
					<td> {$d.datetime.format($T.d.DateModified, "MMM/dd/yyyy")} </td>
				</tr>
				{#/for}
			</table>
		</textarea>
        <!-- template end -->
        <!-- The pagination will be shown here -->
        <div class="PaginationContainer">
        </div>
        <br style="clear: both;" />
    </div>
      <div id="csharp">
        <a class="rotation">
            <img alt="closed" style="height: 12px;" src="../img/closed.png" />C#</a>
        <div class="codeblock">
            <pre name="javascriptcode" class="js:nocontrols">
    [WebMethod]
    public static IEnumerable GetModels(int num)
    {
        //sleep for 5 seconds
        System.Threading.Thread.Sleep(5000);
        NetflixCatalog catalog = new NetflixCatalog(new Uri("http://odata.netflix.com/Catalog/"));
        return catalog.Titles.Take(num);
    }
        </pre>
        </div>
    </div>
    <script type="text/javascript">
        var xhr;
        $(function () {
            //get the return value "xhr"
            xhr = $.doPostback("GetModels", { num: 50 }, {
                //The html showing during the loading
                //call xhr.cancel to abort the request and close the loading tag
                loading_html: '<div id="loading" onclick="xhr.cancel();">Wait for 5 seconds or<br/>Click to cancel</div>',
                callback: function (data) {
                    $("#Container").dataBind($("#template").text(), data.d, {
                        //show pageination in .PaginationContainer
                        page_container: '.PaginationContainer',
                        empty_text: '<span style="color:Red;">No data in the data source.</span>',
                        page_size: 3,
                        page_animation: 'fadein'
                    });
                }
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="javascript" runat="Server">
    <pre name="javascriptcode" class="js:nocontrols">
             var xhr;
        $(function () {
            //get the return value "xhr"
            xhr = $.doPostback("GetModels", { num: 50 }, {
                //The html showing during the loading
                //call xhr.cancel to abort the request and close the loading tag
                loading_html: '<div id="loading" onclick="xhr.cancel();">Wait for 5 seconds or<br/>Click to cancel</div>',
                callback: function (data) {
                    $("#Container").dataBind($("#template").text(), data.d, {
                        //show pageination in .PaginationContainer
                        page_container: '.PaginationContainer',
                        empty_text: '<span style="color:Red;">No data in the data source.</span>',
                        page_size: 3,
                        page_animation: 'fadein'
                    });
                }
            });
        });
	</pre>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="html" runat="Server">
</asp:Content>
